import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-07-15
 * Time: 14:52
 */

//Tomcat会使用的两个端口
//8080业务端口
    //8005管理端口

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf-8");//防止浏览器的字符集不是utf-8，必须在最上边
        resp.getWriter().write("doGet,可以显示中文");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().write("doPost");
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().write("doPut");
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().write("doDelete");
    }


    //    @Override
//    public void init() throws ServletException {
//        System.out.println("首次连接时，只执行一次，后续不再执行");
//    }
//
//    @Override
//    public void destroy() {
//        System.out.println("1. 如果是通过8005管理端口来停止服务器，此时destroy执行" +
//                "2. 如果是直接杀死进程的方式来停止服务器，此时destroy就执行不了");
//    }
//
//    @Override
//    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
//        super.service(req, res);//内部实际调用doGet()，但是一般只重写doGet()
//    }
}
